package com.r2dbc.services;

import com.r2dbc.domain.User;
import com.r2dbc.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/*
 *@Description<p></p>
 *@Author gz
 *@CreateTime 2025/8/12 13:09
 *@CopyRight @2021-2025 卓望信息技术（北京）公司
 */
@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;

    public Mono<User> save(User user) {
        Mono<User> save = userRepository.save(user);
        return save.filter(u -> u.getId() != null);
    }

    public Mono<User> findById(Long id) {
        return userRepository.findById(id);
    }

    public Flux<User> findAll() {
        return userRepository.findAll();
    }

}
